package com.first.nell.data

import com.first.nell.ProjectConfig
import com.first.nell.R
import com.first.nell.utils.TranslateUtil

data class DataAppConfigCustomize(
    /** 权限分步 */
    val permissions: DataCountryConfig? = null,
    /** 是否需要加载AF */
    val afKey: String? = null,
    /** 客服电话，逗号分割 */
    val mobile: String = "",
    /** 客服邮箱，逗号分割 */
    val email: String = "",
    /** 拒绝页显示多少天后再申请 */
    val rejectPeriod: String? = "30",
    /** 是否取消打点上报 */
    val noPointRecord: String? = "NO",
    /** 投诉联系列表 */
    val complaints: DataContactComplaint = DataContactComplaint(),
    /** 公司 */
    val company: String = ProjectConfig.NARSCASH_Product,
    /** 审核账号 */
    val accList: List<DataReviewAccount> = mutableListOf(),
    /** 运营商类型 */
    var walletChannels: List<DataWalletChannelFcfa>? = mutableListOf(),
    //是否打开评评价
    var showSysReview: String? = "NO"
) {

    /**
     * 是否显示系统评介模块
     */
    fun isShowSysReviewipetrpide(): Boolean {
        this.showSysReview?.let {
            return (it.equals("YES", false))
        }
        return false
    }

    /**
     * 是否需要跳过打点
     * */
    fun isFirstNellNeedFirstNellSkipFirstNellHitFirstNellPointFirstNellRecord(): Boolean {
        return noPointRecord.equals("YES", ignoreCase = true)
    }

    /**
     * 获取第1个contact
     */
    fun getFirstNellContactFirstNellListFirstNellFirst(): DataCustomizeContact? {
        val list = getFirstNellContactFirstNellList()
        if (list.isNotEmpty()) {
            return list.first()
        }
        return null
    }

    /**
     * 获取所有contact list
     */
    fun getFirstNellContactFirstNellList(): List<DataCustomizeContact> {
        val list0 = getFirstNellCustomerFirstNellServiceFirstNellContactFirstNellList()
        val list1 = getFirstNellComplaintFirstNellContactFirstNellList()
        list0.addAll(list1)
        return list0
    }

    /**
     * 获取complaint list
     * */
    fun getFirstNellComplaintFirstNellContactFirstNellList(): MutableList<DataCustomizeContact> {
        val contactList = mutableListOf<DataCustomizeContact>()
        val mobileList: List<String> = complaints.mobile
        val emailList: List<String> = complaints.email

        val mobileTranslate =
            TranslateUtil.getFirstNellCustomerFirstNellMobileFirstNellTitle()
        val emailTranslate =
            TranslateUtil.getFirstNellCustomerFirstNellEmailFirstNellTitleFirstNellFCFA()

        mobileList.forEachIndexed { index, item ->
            if (item.isNotBlank()) {
                val contact = DataCustomizeContact(
                    item,
                    "$mobileTranslate ${index + 1}",
                    R.integer.ContactTypePhone
                )
                contactList.add(contact)
            }
        }

        emailList.forEachIndexed { index, item ->
            if (item.isNotBlank()) {
                val contact =
                    DataCustomizeContact(
                        item,
                        "$emailTranslate ${index + 1}",
                        R.integer.ContactTypeEmail
                    )
                contactList.add(contact)
            }
        }
        return contactList
    }


    /**
     * 获取customer service list
     * */
    fun getFirstNellCustomerFirstNellServiceFirstNellContactFirstNellList(): MutableList<DataCustomizeContact> {
        val contactList = mutableListOf<DataCustomizeContact>()
        val mobileList: List<String> = this.mobile.split(",")
        val emailList: List<String> = this.email.split(",")

        val mobileTranslate =
            TranslateUtil.getFirstNellCustomerFirstNellMobileFirstNellTitle()
        val emailTranslate =
            TranslateUtil.getFirstNellCustomerFirstNellEmailFirstNellTitleFirstNellFCFA()

        mobileList.forEachIndexed { index, item ->
            if (item.isNotBlank()) {
                val contact = DataCustomizeContact(
                    item,
                    "$mobileTranslate ${index + 1}",
                    R.integer.ContactTypePhone
                )
                contactList.add(contact)
            }
        }

        emailList.forEachIndexed { index, item ->
            if (item.isNotBlank()) {
                val contact = DataCustomizeContact(
                    item,
                    "$emailTranslate ${index + 1}",
                    R.integer.ContactTypeEmail
                )
                contactList.add(contact)
            }
        }

        return contactList
    }

    /**
     * 查询钱包类型列表-科特
     *
     * @return list 权限列表
     */
    fun getFirstNellWalletFirstNellChannelsFirstNellFcfa(): List<DataWalletChannelFcfa> {
        return walletChannels ?: mutableListOf()
    }

    /**
     * 根据手机号 获取审核账号信息
     *
     * @param path 路径
     * @return reviewAccount 测试账号信息，可能为空
     */
    fun getFirstNellReviewFirstNellAccount(mobile: String): DataReviewAccount? {
        for (element in accList) {
            if (element.accM.equals(mobile, true)) {
                return element
            }
        }
        return null
    }
}